﻿using System.Collections.Generic;

namespace Microsoft.Xna.Framework.Graphics
{
	/// <summary>
	/// Manipulates a collection of EffectAnnotation objects.
	/// </summary>
	public sealed class EffectAnnotationCollection : IEnumerable<EffectAnnotation>
	{
		#region Fields
		private List<EffectAnnotation> pAnnotation;
		#endregion

		#region Properties
		/// <summary>
		/// Gets the number of EffectAnnotation objects in this EffectAnnotationCollection.
		/// </summary>
		public int Count
		{
			get { return pAnnotation.Count; }
		}

		/// <summary>
		/// Gets a specific EffectAnnotation object by using an index value.
		/// </summary>
		/// <param name="index">Index of the EffectAnnotation to get.</param>
		public EffectAnnotation this[int index]
		{
			get
			{
				if ((index >= 0) && (index < this.pAnnotation.Count))
				{
					return this.pAnnotation[index];
				}
				return null;
			}
		}

		/// <summary>
		/// Gets a specific EffectAnnotation object by using a name.
		/// </summary>
		/// <param name="name">Name of the EffectAnnotation to get.</param>
		public EffectAnnotation this[string name]
		{
			get
			{
				List<EffectAnnotation>.Enumerator enumerator = this.pAnnotation.GetEnumerator();
				if (enumerator.MoveNext())
				{
					do
					{
						EffectAnnotation current = enumerator.Current;
						if (current._name == name)
						{
							return current;
						}
					}
					while (enumerator.MoveNext());
				}
				return null;
			}
		}
		#endregion

		#region Constructor
		internal EffectAnnotationCollection(int count)
		{
			pAnnotation = new List<EffectAnnotation>(count);
		}
		#endregion

		#region Private Methods
		IEnumerator<EffectAnnotation> IEnumerable<EffectAnnotation>.GetEnumerator()
		{
			return pAnnotation.GetEnumerator();
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return pAnnotation.GetEnumerator();
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Gets an enumerator that can iterate through the EffectAnnotationCollection.
		/// </summary>
		public List<EffectAnnotation>.Enumerator GetEnumerator()
		{
			return pAnnotation.GetEnumerator();
		}
		#endregion
	}
}
